package com.andnnl.springbootdemo.action;

import com.andnnl.springbootdemo.utils.JsonBuilder;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Map;

/**
 * Created by chenss on 2019/3/1.
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    private final String SYSTEM_ERR = "系统异常处理,请联系管理员";



//    @ExceptionHandler({Exception.class})
////    @ResponseBody
//    public String errorHandler(Exception ex) {
//        //do something
////        return SYSTEM_ERR;
//        System.out.println(SYSTEM_ERR);
//        return  JsonBuilder.builder().put("code", 500).put("msg", SYSTEM_ERR).build();
//    }

    @ExceptionHandler({Exception.class})
    public Map<String,Object> errorHandler(Exception ex) {
        //do something
//        return SYSTEM_ERR;
        System.out.println(SYSTEM_ERR);
        return  JsonBuilder.builder().put("code", 500).put("msg", SYSTEM_ERR).buildMap();
    }



}
